import express from 'express'
const router = express.Router()
// 成功 和 失败的 规范化格式
import SuccessModel from '../module/SuccessModel.js'
import ErrorModel from '../module/ErrorModel.js'
import knex from '../utils/myKenx.js'

/* 词云记录添加 */
router.post('/ciyun', (req, response) => {
  const { name } = req.body
  knex('ciyun')
    .insert({ name })
    .then(res => {
      response.send(new SuccessModel({ msg: '添加成功', data: res }))
      console.log('词云add接口调用成功!   ' + new Date().toLocaleString())
    })
    .catch(err => {
      console.log(err)
      response.send(new ErrorModel({ msg: '添加失败' }))
    })
})

/* 词云列表查询 */
router.get('/ciyun', (req, response) => {
  const { name } = req.body
  knex('ciyun')
    .select()
    .then(res => {
      response.send(new SuccessModel({ msg: '查询成功', data: res }))
      console.log('词云查询接口调用成功!   ' + new Date().toLocaleString())
    })
    .catch(err => {
      console.log(err)
      response.send(new ErrorModel({ msg: '查询失败' }))
    })
})

export default router
